//
// Created by xili on 2024/9/19 14:39.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    int minimumEffort(vector <vector<int>> &tasks) {
        sort(tasks.begin(), tasks.end(),
             [](vector<int> &a, vector<int> &b) { return a[1] - a[0] < b[1] - b[0]; });
        int ans = 0;
        for (auto &it: tasks) {
            ans = max(ans + it[0], it[1]);
        }
        return ans;
    }
};